{% extends 'wanplus/wangwangba/base_nav_frame.html' %}
{% load staticfiles %}
{% block content %}
  <p>内容</p>
  <div>
    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 class="wb-panel-wigdet">内容清单</h4>
        <div class="wb-panel-wigdet-right">
          <button class="btn btn-default" type="button" id="content-add-btn"><span class="fa fa-plus"></span></button>
        </div>
        <div class="clearfix"></div>
      </div>
      <table class="table table-hover table-striped" id="wwb-content-list"></table>
    </div>
  </div>
{% endblock %}
{% block jsscript %}
  <script type="text/javascript">
  var STATE = [
    "待处理", "预发布", "已上线", "已下线"
  ];
  $(document).ready(function(e) {
   var contentList = $("#wwb-content-list").table({
     columnKeys : ["code", "name", "type", "category", "state", "operations"]
     , columnNames : ["编码", "名称", "类型", "栏目", "状态", "操作"]
     , columnBody : function (key, value, data) {
       switch (key) {
         case 'recommend':
           if (value) {
             return $("<span />").addClass("fa fa-check");
           } else {
             return "";
           }
         case 'state':
           switch (parseInt(value)) {
             case 0:
             case 1:
             case 2:
             case 3:
               return STATE[parseInt(value)];
             default:
               return ''
           }
         case 'operations':
           var span = $("<span />").addClass("fa fa-pencil-square-o");
           var a = $("<a />").attr({
             href : "./content/editor?token=" + data["token"]
           });
           a.append(span);
           return a;
         case 'type':
           switch (parseInt(value)) {
             case 1 :
               return "视频";
             case 2 :
               return "分页文本";
             case 3 :
               return "优惠订购";
             default :
               return "";
           }
         default :
           return value;
       }
     }
   });

   $.ajax({
     url : "./content/list"
     , type : "get"
     , dataType : "json"
     , success : function (data) {
       if (data.resultCode == 1) {
         var list = $.wUtils.getListData(data);
         contentList.load(list);
       }
     }
     , error : function () {}
   });

   $("#content-add-btn").click(function(e) {
     window.location.href = './content/editor';
   });
  });
  </script>
{% endblock %}